<template>
  <div class="header">
    <div class="back" @click="$router.back()">
        <i class="iconfont icon-jiantou_liebiaoxiangzuo"></i>
    </div>
    <div class="list">
      <a @click="goTo(item.position,index)" href="javascript:;" v-for="(item,index) in list" :key="item.id" :class="{active:listIndex==index}">
        {{ item.tit }}
      </a>
    </div>
    <div class="collect">
        <i class="iconfont icon-xin"></i>
        <i class="iconfont icon-fenlei"></i>
    </div>
  </div>
</template>

<script>
import bus from '@/event'
export default {
  data() {
    return {
      list: [
        {
          id: "001",
          tit: "商品",
          position:'detail_0'
        },
        {
          id: "002",
          position:'detail_1',
          tit: "评价",
        },
        {
          id: "003",
          tit: "详情",
          position:'detail_2'
        },
        {
          id: "004",
          tit: "推荐",
          position:'detail_3'
        },
      ],
      listIndex:0
    };
  },
  methods: {
    goTo(id,index){
      // this.listIndex = index
      bus.$emit('go',id)
    }
  },
  mounted () {
    bus.$on('changeIndex',(val)=>{
      this.listIndex = val
    })
  }
};
</script>

<style lang="less" scoped>
.header {
  height: 5rem;
  width: 100%;
  display: flex;
  position: fixed;
  z-index: 2;
  top: 0;
  background-color: #fff;
  .back {
    width: 7rem;
    height: 5rem;
    // background-color: pink;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #979797;
    i{
        font-size: 2.5rem;
        // margin-top: 1rem;
    }
  }
  .list {
    flex: 1;
    // background-color: yellow;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #555555;
    span {
      flex: 1;
      text-align: center;
      font-size: 1.5rem;
    }
    .active {
      font-weight: 600;
      position: relative;
      font-size: 1.6rem;
      color: red;
      &::after {
        content: "";
        position: absolute;
        left: 50%;
        bottom: -0.5rem;
        transform: translateX(-50%);
        width: 3rem;
        height: 0.3rem;
        background: linear-gradient(90deg, #f91f28, rgba(255, 79, 46, 0.35));
      }
    }
  }
  .collect {
    width: 8rem;
    height: 5rem;
    // background-color: red;
    display: flex;
    justify-content:space-around;
    align-items: center;
    color: #7f7f7f;
    i{
        font-size:2rem;
    }
  }
}
</style>